﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using NHibernateDB;

namespace WSPersoaneTrimitere
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public PersoanaTrimitere[] PersoanaTrimitere()
        {
            string clientIP = HttpContext.Current.Request.UserHostAddress;
            XMLParser parser = new XMLParser();
            if (!parser.ClientExist(clientIP))
                return null;

            try
            {
                PersistenceManager pm = PersistenceManager.Instance;
                IList<PersoanaTrimitere> st = pm.RetrieveAll<PersoanaTrimitere>(SessionAction.BeginAndEnd);
                return st.ToArray();
            }
            catch
            {
                return null;
            }
        }

        [WebMethod]
        public PersoanaTrimitere[] PersoanaTrimitereByCNPPacient(string CNP)
        {
            string clientIP = HttpContext.Current.Request.UserHostAddress;
            XMLParser parser = new XMLParser();
            if (!parser.ClientExist(clientIP))
                return null;

            try
            {
                PersistenceManager pm = PersistenceManager.Instance;
                IList<PersoanaTrimitere> st = pm.RetrieveEquals<PersoanaTrimitere>("IdPacient", CNP);
                return st.ToArray();
            }
            catch
            {
                return null;
            }
        }

        [WebMethod]
        public PersoanaTrimitere[] PersoanaTrimitereByID(int ID)
        {
            string clientIP = HttpContext.Current.Request.UserHostAddress;
            XMLParser parser = new XMLParser();
            if (!parser.ClientExist(clientIP))
                return null;

            try
            {
                PersistenceManager pm = PersistenceManager.Instance;
                IList<PersoanaTrimitere> st = pm.RetrieveEquals<PersoanaTrimitere>("Id", ID);
                return st.ToArray();
            }
            catch
            {
                return null;
            }
        }
    }
}
